#coding=UTF-8
import requests
import json

# 引入自定义的keystone模块
import keystone
keystone_s=keystone.getToken()

#nova(compute)端点地址：
glance_url="http://192.168.100.10:9292/v2/images"
#定义请求头
headers={
    "X-Auth-Token":keystone_s['token']
}
#发送请求
req=requests.get(glance_url,headers=headers)
#格式化打印响应
print(json.dumps(req.json(),sort_keys=True,indent=4))

if req.status_code==200:
    #打印镜像总数
    print("images:" + str(len(req.json()['images'])))
    #循环打印镜像列表
    for i in req.json()['images']:
        print("image name:",str(i['name']),"id:",str(i['id']))